$(document).ready(function(){
	console.log('in custom.js')
	
	//js for index page


	//custom js for photo detail page
	

	$('.get-qr-button').click(function(){ 
		var canvas = document.getElementById('mainImage');
		var image = canvas.toDataURL("image/png")
		//imageToUpload = $(new Image()).attr('src', image)
		uploadImage(image);
	});

	//send image data to server and generate qr code
	function uploadImage(imageToUpload){
		var photoid = Math.round(Math.random() * 1000000000);
		//console.log(photoid);
		$.ajax({
			type: 'POST',
			url: '../photo/' + photoid,
			data: {
				imgBase64: imageToUpload
			}
		}).done(function(res){
			appendQrCode(res.qrpath);
			console.log('file uploaded');
		})
	};

	function appendQrCode(path){
		var myQr = new Image();
		myQr.src = '../' + path + '.png';
		//myQr.src = "../images/qr/168160858.png"
		if ( $('#qrModalBody').find($('img')) ){
			$('#qrModalBody').empty();
		}
		$('#qrModalBody').append(myQr);
		$('.qr-modal').addClass('active')
	}

	$('#closeModal').on('click', function(){
		if ( $('.qr-modal').hasClass('active') ){
			$('.qr-modal').removeClass('active')
		}
	})

	function uploadFilteredImage(){
	}

})